﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Model;

namespace Truextend.CoffeShop.DataAccess
{
    public static class RestaurantsDataAccess
    {
        static CoffeShopEntities db = new CoffeShopEntities();

        public static List<Restaurant> GetExternalRestaurant() {

            List<Restaurant> listRestaurants = new List<Restaurant>();

            try {

                listRestaurants = (from p in db.Restaurant where p.RestaurantId != 1 select p).ToList();
            
            }catch(Exception) { }

            return listRestaurants;
        }

        public static Restaurant GetRestaurantByOrderId(int orderId) {

            Restaurant restaurant = new Restaurant();

            try {
                restaurant = (from p in db.Restaurant
                              join h in db.Product on p.RestaurantId equals h.Restaurant.RestaurantId
                              join i in db.Detail on h.ProductId equals i.Product.ProductId
                              where i.Order.OrderId == orderId
                              select p).First();
            }
            catch (Exception) { }

            return restaurant;
        }
    }
}
